package com.atguigu.gmallre.mock.config;


import com.atguigu.mock.util.ParamUtil;
import com.atguigu.mock.util.RandomNumBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Configuration
public class AppConfig {


    //public static Date date=new Date();
    public static Long user_session_count = 1000L;

    public static String mock_clear_user = "0";

    public static String mock_clear_busi = "0";



    public static Integer mock_new_user = 0;

    public static Integer mock_user_update_rate=15;

    public static String mock_date_str = "";

    public static Date mock_date = new Date();

    public static Integer mock_count = 1000;

    public static String mock_log_type = "file";

    public static String mock_log_http_url = "http://localhost:80";

    public static Integer max_mid = 500;

    public static Integer max_uid = 500;




    public static Integer page_during_max_ms = 20000;


    public static Integer error_rate = 3;

    public static Integer if_realtime = 0;

    public static Integer[] start_time_weight;

    public static Integer[] payment_type_weight;

    public static Integer video_heart_interval_sec = 30;

    public static Integer if_study = 50;

    public static Integer exam_corrent_rate = 50;

    public static Integer log_sleep = 100;

    public static Integer if_favor_rate = 30;

    public static Integer if_favor_cancel_rate = 10;

    public static Integer if_cart_rate = 70;

    public static Integer if_order_rate = 70;

    public static Integer if_payment_rate = 80;

    public static Integer if_cart_add_num_rate = 10;

    public static Integer if_cart_minus_num_rate = 10;

    public static Integer if_cart_rm_rate = 10;

    public static Integer if_refund_rate=30;

    public static Integer if_add_address = 15;

    public static Integer if_get_coupon = 25;

    public static Integer max_display_count = 10;

    public static Integer min_display_count = 4;

    public static Integer max_activity_count = 2;
    public static Integer max_pos_id = 5;

    public static  Integer if_nologin_rate=50;

    public static  Integer if_noregister_when_nologin_rate=50;



    public static Integer[] appraise_weight = new Integer[]{80, 10, 4, 1,5};

    public static Integer[] sourceTypeRate;

    public static Integer[] vipThreshold = new Integer[]{50, 150, 500, 1000};

    public static Integer[] referWeight;

    public static String[] searchKeywords;

    public static String kafka_server;
    public static String kafka_topic;


//    public static Integer[] skuWeightMale;
//    public static Integer[] skuWeightFemale;


    public static Integer[] tmWeightMale;
    public static Integer[] tmWeightFemale;


    public static RandomNumBuilder skuRandomBuilderF;  // 会在skuService进行初始化
    public static RandomNumBuilder skuRandomBuilderM;  //

    public static RandomNumBuilder referRandomBuilder;

    public static boolean isLogDb;

    public static String logDbTableName;


    @Value("${mock.start-time-weight}")
    public void setStartTimeWeight(String start_time_weight) {
        AppConfig.start_time_weight =  ParamUtil.checkRate(start_time_weight) ;
    }


    @Value("${mock.payment-type-weight}")
    public void setPaymentTypeWeight(String payment_type_weight) {
        AppConfig.payment_type_weight =  ParamUtil.checkRate(payment_type_weight) ;
    }

    @Value("${mock.user-session.count}")
    public void setUserSessionCount(Long user_session_count) {
        AppConfig.user_session_count = user_session_count;
    }

    @Value("${mock.new.user}")
    public void setNewUser(String newUser) {
        AppConfig.mock_new_user = ParamUtil.checkCount(newUser);
    }

    @Value("${mock.if-realtime}")
    public void setIfRealtime(Integer ifRealtime) {
        AppConfig.if_realtime = ifRealtime;
    }

    @Value("${mock.clear.user}")
    public void setMockClearUser(String mockClearUser) {
        AppConfig.mock_clear_user = mockClearUser;
    }

    @Value("${mock.clear.busi}")
    public void setMockClearBusi(String mockClearBusi) {
        AppConfig.mock_clear_busi = mockClearBusi;
    }

    //
    @Value("${mock.tm-weight.male}")
    public   void setSkuWeightMale(String tmWeightMaleStr) {
        Integer[] tmWeightMaleArray = ParamUtil.checkRate( tmWeightMaleStr );
        AppConfig.tmWeightMale = tmWeightMaleArray;
    }

    @Value("${mock.tm-weight.female}")
    public   void setSkuWeightFemale(String tmWeightFemaleStr) {
        Integer[] tmWeightFemaleArray = ParamUtil.checkRate( tmWeightFemaleStr );
        AppConfig.tmWeightFemale = tmWeightFemaleArray;
    }
//
    @Value("${mock.log.type}")
    public   void setMock_type(String mock_type) {
        AppConfig.mock_log_type = mock_type;
    }

    @Value("${mock.log.http.url}")
    public   void setMock_url(String mock_url) {
        AppConfig.mock_log_http_url = mock_url;
    }

    @Value("${mock.log.kafka.server}")
    public   void setKafka_server(String kafka_server) {
        AppConfig.kafka_server = kafka_server;
    }
    @Value("${mock.log.kafka.topic}")
    public   void setKafka_topic(String kafka_topic) {
        AppConfig.kafka_topic = kafka_topic;
    }

    @Value("${mock.if-favor-rate}")
    public  void setIf_favor_rate(String if_favor_rate) {
        AppConfig.if_favor_rate = ParamUtil.checkRatioNum( if_favor_rate);
    }
    @Value("${mock.if-cart-rate}")
    public  void setIf_cart_rate(String if_cart_rate) {
        AppConfig.if_cart_rate = ParamUtil.checkRatioNum( if_cart_rate);
    }

    @Value("${mock.if-order-rate}")
    public  void setIf_order_rate(String if_order_rate) {
        AppConfig.if_order_rate = ParamUtil.checkRatioNum( if_order_rate);
    }


    @Value("${mock.if-refund-rate}")
    public  void setIf_refund_rate(String if_refund_rate ) {
        AppConfig.if_refund_rate = ParamUtil.checkRatioNum( if_refund_rate);
    }
//
    public  void setIf_favor_cancel_rate(String if_favor_cancel_rate) {
        AppConfig.if_favor_cancel_rate = ParamUtil.checkRatioNum( if_favor_cancel_rate);
    }

    @Value("${mock.date}")
    public void setMockDate(String mockDate) {

        AppConfig.mock_date_str = mockDate;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            AppConfig.mock_date = simpleDateFormat.parse(mockDate);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new RuntimeException("日期格式不对！");
        }

    }

    @Value("${mock.search.keyword}")
    public void setSearchKeywords(String keywords){
        AppConfig.searchKeywords= ParamUtil.checkArray(keywords);
    }

    @Value("${mock.refer-weight}")
    public void setReferWeight(String referWeight){
        AppConfig.referWeight= ParamUtil.checkRate(referWeight);
        AppConfig.referRandomBuilder=new RandomNumBuilder(1,5,AppConfig.referWeight);
    }

    @Value("${mock.log.db.enable}")
    public   void setLogDb(String logDb) {
        AppConfig.isLogDb = ParamUtil.checkBoolean(logDb)  ;
    }




}
